package com.huimingpay.merchant.controller;

import com.huimingpay.merchant.api.AppService;
import com.huimingpay.merchant.common.utils.SecurityUtil;
import com.huimingpay.merchant.dto.AppDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:AppController
 * Package:com.huimingpay.merchant.controller
 * Time: 2024/7/23
 */

@RestController
@Slf4j
@Api(value = "商户平台-应用管理", tags = "商户平台-应用相关")
public class AppController {
    @Reference
    AppService appService;

    @ApiOperation("商户创建应用")
    @ApiImplicitParam(name = "app", value = "应用信息", required = true, dataType = "AppDTO", paramType = "body")
    @PostMapping(value = "/app/create")
    public AppDTO createApp(@RequestParam("appName") String appName, @RequestParam("publicKey") String publicKey) {
        // 1、获取merchantId
        Long merchantId = SecurityUtil.getMerchantId();
        // 2、创建应用
        AppDTO app = new AppDTO();
        app.setAppName(appName);
        app.setPublicKey(publicKey);
        return appService.createApp(merchantId,app);
    }

    @ApiOperation("查询商户下的应用列表")
    @GetMapping(value = "/app/queryByMerchantId")
    public List<AppDTO> queryMyApps() {
        Long merchantId = SecurityUtil.getMerchantId();
        return appService.queryAppsByMerchantId(merchantId);
    }


    @ApiOperation("根据应用id查询应用信息")
    @ApiImplicitParam(value = "应用id",name = "appId",dataType = "String",paramType = "path")
    @GetMapping(value = "/app/{appId}")
    public AppDTO getApp(@PathVariable("appId") String appId) {
        return appService.getAppByAppId(appId);
    }



}
